import Vue from 'vue';
import ViewUI from 'view-design';
import VueRouter from 'vue-router';
import router from './router';
import Store from './store'
import { Rest } from './libs/Request'
import { enums } from './libs/Enum'
import Dict from './libs/Dict'
import App from './app.vue'
import 'view-design/dist/styles/iview.css';
import './libs/Calculate'
import util from './libs/util';
import * as echarts from 'echarts';
import HigPager from './component/HigPager'
// import FileSaver from 'file-saver'
// import XLSX from 'xlsx'
// import Print from 'vue-print-nb'

// Vue.use(Print);
Vue.use(VueRouter);
Vue.use(ViewUI);
// vue中导出excel表格模板

/**
 * 注册全局组件
 */
Vue.component('HigPager', HigPager)

/**
 * Vue全局属性
 */
// Vue.prototype.$FileSaver = FileSaver //excel表格下载
// Vue.prototype.$XLSX = XLSX //excel表格导出
Vue.prototype.$bus = new Vue()
Vue.prototype.$echarts = echarts
Vue.prototype.$store = Store
Vue.prototype.$dict = Dict
Vue.prototype.$rest = Rest
Vue.prototype.$enum = enums
Vue.prototype.$date = util.dateFormat
Vue.prototype.$cash = util.cashFormat
Vue.prototype.$size = util.sizeFormat
Vue.prototype.$phone = util.phoneHide

router.beforeEach((to, from, next) => {
    if(to.meta.open){
        ViewUI.LoadingBar.start();
        util.title(to.meta.title);
        next();
        return false
    }
        
    if(Store.getToken()){
        ViewUI.LoadingBar.start();
        util.title(to.meta.title);
        next()
        return false
        // if(util.checkRouter(to.name,Store.getUser('powers'))){
        //     ViewUI.LoadingBar.start();
        //     util.title(to.meta.title);
        //     next()
        //     return false
        // } else {
        //     console.warn('无权限访问 ->',to.name)
        //     // next({name: 'power-index'})  
        //     next()
        //     return false
        // }
    }
    // next({name: 'login'})
});

router.afterEach((to, from, next) => {
    ViewUI.LoadingBar.finish();
    window.scrollTo(0, 0);
});

new Vue({
    el: '#app',
    router: router,
    render: h => h(App)
})

